package com.itheima.tlias84.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.tlias84.dto.SelectAllClazzDTO;
import com.itheima.tlias84.dto.SelectClassByIdDTO;
import com.itheima.tlias84.dto.SelectClazzDTO;
import com.itheima.tlias84.mapper.ClazzMapper;
import com.itheima.tlias84.po.InsertClazzParam;
import com.itheima.tlias84.po.SelectClazzPageParam;
import com.itheima.tlias84.po.UpdateClazzParam;
import com.itheima.tlias84.service.ClazzService;
import com.itheima.tlias84.utils.ResultUtil;
import com.itheima.tlias84.vo.PageVO;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Slf4j
@Service
public class ClazzServiceImpl implements ClazzService {
    @Resource
    ClazzMapper clazzMapper;
    @Override
    public ResultUtil selectClazzByPage(SelectClazzPageParam param) {
        Page<Object> page = PageHelper.startPage(param.getPage(), param.getPageSize());
        List<SelectClazzDTO> selectClazzDTOS = clazzMapper.selectClazzByPage(param);

        PageVO<SelectClazzDTO> pageVO = new PageVO<>();
        pageVO.setTotal(page.getTotal());
        pageVO.setRows(selectClazzDTOS);
        return ResultUtil.success(pageVO);
    }

    @Override
    public List<SelectAllClazzDTO> selectAllClazz() {
        return clazzMapper.selectAllClazz();
    }

    @Override
    public SelectClassByIdDTO selectClazzById(Integer id) {
        return clazzMapper.selectClazzById(id);
    }

    @Override
    public int insertOneClazz(InsertClazzParam param) {
        param.setCreateTime(LocalDateTime.now());
        param.setUpdateTime(LocalDateTime.now());
        return clazzMapper.insertOneClazz(param);
    }

    @Override
    public int updateClazz(UpdateClazzParam param) {
        param.setUpdateTime(LocalDateTime.now());
        return clazzMapper.updateClazz(param);
    }

    @Override
    public int deletebatch(Integer id) {
        return clazzMapper.deleteBatch(id);
    }
}
